<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp" %>
<%-- <%@ taglib prefix="c"uri="http://java.sun.com/jstl/core" %> --%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta charset="UTF-8"/>
    <title>仓库地址列表</title>
    <link href="${ctx}/static/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link href="${ctx}/static/dist/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
    <link href="${ctx}/static/plugins/datatables/css/matrix-style.css" rel="stylesheet" type="text/css" />
    <link href="${ctx}/static/dist/css/AdminLTE.css" rel="stylesheet" type="text/css" />
    <link href="${ctx}/static/plugins/datatables/css/dataTables.bootstrap.css" rel="stylesheet" type="text/css" />
        <link href="${ctx}/static/plugins/layer/skin/default/layer.css" rel="stylesheet" type="text/css"/>
    <style>
        button.searching{
            background-color:#666
        }
    </style>
</head>
<body>
<div class="widget-box">
	<div class="widget-content nopadding">
		<table style="line-height:45px;font-size:12px;">
			<tr>
				<td>
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class="btn btn-primary" href="${ctx}/api/warehouseAddress/addPage">新增</a>
				</td>	
				<td>
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class="btn btn-primary" onclick="batchDelete()">删除</a>
				</td>		
			</tr>
		</table>
	</div>
</div>
 <div class="row">
		 <div class="col-xs-12">
		 	<div class="box">
		 		<div class="box-header">
	                 <h3 class="box-title">仓库地址列表</h3>
	             </div>
	             <!-- 列表 -->
	             <div class="box-body table-responsive">
	             	<table id="dataTables" class="table table-bordered table-hover">
	             	</table>
	             </div>
		 	</div>
		 </div>
	</div>
<script src="${ctx}/static/plugins/jQuery/jQuery-2.1.4.min.js"></script>
<script src="${ctx}/static/bootstrap/js/bootstrap.min.js"></script>
<!-- datatable -->
<script src="${ctx}/static/plugins/datatables/jquery.dataTables.js" type="text/javascript"></script>
<script src="${ctx}/static/plugins/datatables/dataTables.bootstrap.js" type="text/javascript"></script>
<script src="${ctx}/static/plugins/layer/layer.js"></script>
<script>
   var tb;
   var classifyLevel = 1;
   $(function () {
		//列表初始化
		tb = $('#dataTables').dataTable({
				"bServerSide": true,
				"destroy": true,//如果需要重新加载的时候请加上这个
				"sPaginationType": "full_numbers",
				"bJQueryUI": true,
				"bAutoWidth": true,//自动宽度
				"bSort": false, //排序功能
				"sDom": '<"">t<"F"ip>',
				"sAjaxSource":  "${ctx}/api/warehouseAddress/pagelist", //ajax调用接口
				"aoColumnDefs": [{sDefaultContent: '',aTargets: [ '_all' ]}],
				"aoColumns": [
       				{ "sTitle" : "<input type='checkbox'  id='titleId'/>","mData": "id" ,"class":"sClass","mRender":function(data, type, full){
					  		return "<input type='checkbox'  name='checkOne'  value='"+full.id+"'/>";
						}
				  	},
				  	{ "sTitle" : "序号", 	 "mData": "id" ,"class":"sClass"},
	                { "sTitle" : "联系人","mData": "contacts","class":"sClass" },
	                { "sTitle" : "手机号","mData": "telPhone","class":"sClass" },
	                { "sTitle" : "座机号","mData": "phoneNo","class":"sClass" },
	                { "sTitle" : "联系地址","mData": "address","class":"sClass", "mRender": function (data, type, full) {
	                    var text;
	                    if (full.provinceName != null) {
	                        text = full.provinceName
	                    }
	                    if (full.cityName != null) {
	                        text += "-" + full.cityName
	                    }
	                    if (full.countyName != null) {
	                        text += "-" + full.countyName
	                    }
	                    if (full.address != null) {
	                        text += "-" + full.address
	                    }
	                    return text;
	                }
	                },
	                {
	                    "sTitle": "是否默认地址", "mData": "isDefault", "class": "sClass", "mRender": function (data, type, full) {
	                    var text;
	                    if (full.isDefault == '1') {
	                        text = "<font>是</font>";
	                    } else if (full.isDefault == '2') {
	                        text = "<font>否</font>"
	                    }
	                    return text;
	                }
	                },
	                {
	                    "sTitle": "是否提货点", "mData": "isDeliveryPoint", "class": "sClass", "mRender": function (data, type, full) {
	                    var text;
	                    if (full.isDeliveryPoint == '1') {
	                        text = "<font>是</font>";
	                    } else if (full.isDeliveryPoint == '2') {
	                        text = "<font>否</font>"
	                    }
	                    return text;
	                }
	                },
	                {"sTitle" : "操作","mData" : "id", "mRender" : function ( data, type, full ) {
                	  var text = '<div class="btn-group" style="text-align:left;"><button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown">操作 <span class="caret"></span></button>';
						  text = text+'<ul class="dropdown-menu" role="menu">';
	                      text += '<li><a href="${ctx}/api/warehouseAddress/updatePage?id=' + full.id + '&userId='+full.userId+'">修改</a> </li>';
							 if(full.isDefault == 2){
	 							  text += '<li class="divider"></li>';
	 							  text += '<li><a href="#" onclick="updateDefault(\''+full.id+'\',\''+full.userId+'\');">设为默认地址</a> </li>';
						  }
							 if(full.isDeliveryPoint == 2){
	 							  text += '<li class="divider"></li>';
	 							  text += '<li><a href="#" onclick="updateDeliveryPoint(\''+full.id+'\');">设为提货点</a> </li>';
						  }
							  text += '<li class="divider"></li>';
							  text += '<li><a href="#" onclick="deleteById(\''+full.id+'\');">删除</a> </li>';
						  text = text + '</ul></div>';
						  return text;
						} 
	                }
            ],
		        "oLanguage" : {
		           "sProcessing" : "数据加载中······",
		           "sLengthMenu" : "显示 _MENU_ 条记录",
		           "sZeroRecords" : "没有您要搜索的内容！",
		           "sEmptyTable" : "列表中无数据存在！",
		           "sInfo" : "当前显示 _START_ 到 _END_ 条数据，共 _TOTAL_ 条数据",
		           "sInfoEmpty" : "显示 0 到 0 条记录",
		           "sInfoFiltered" : "数据列表中共  _MAX_ 条记录",
		           "oPaginate" : {
		               "sFirst" : "首页",
		               "sPrevious" : "上一页",
		               "sNext" : "下一页",
		               "sLast" : "末页"
		           }
		        },
		        "fnServerData" : function ( sSource, aoData, fnCallback, oSettings ) {
					oSettings.jqXHR = $.ajax( {
						"dataType" 	: 'json',
						"type" 		: "GET",
						"async"     : 'false',
						"url" 		: sSource,
						"data" 		: {
							'pageNum': (aoData[3].value/aoData[4].value)+1,
							'pageSize' :  aoData[4].value,
							'productName'  :  $("#productName").val(),
// 							'productForm'  :  $("#productForm").val(),
							'productClassifyId'  :  $("#classify"+classifyLevel).val(),
// 							'isable': 1,
							'supplierExtendsId': $("#supplierId").val()
						}, 
						"success"	: fnCallback
					} );
				},
		  });
		

		$("#titleId").click(function() {
			if (this.checked) {
				$("input[name='checkOne']").each(function() {
					this.checked = true;
				});
			} else {
				$("input[name='checkOne']").each(function() {
					this.checked = false;
				});
			}

		});
		
   });
		   
		   //条件查询重新加载数据
		   function query() {
		 	  tb.fnDraw();
		   };
		   
		   //设置默认地址
		   function updateDefault(id,userId){
			   if(confirm("确认设置为默认地址吗")==true){
			  		 $.ajax({
			  			 async:false,
			       		url:"/api/warehouseAddress/updateWarehouseDefault",
			       		data:{id:id,isDefault:1,userId:userId},
			       		type:"POST",
			       		dataType:"json",
			       		success:function(data){
			       			if(data.code=="200"){
			       				tb.fnDraw();
			       			}else{
			       				alert(data.message);
			       			}
			       		}
			  		 });
			  		 return;
			  	 }else{
			  		 return false;
			  	 }
		   }
		   
		   //设置提货点
		   function updateDeliveryPoint(id){
			   if(confirm("确认设置为提货点吗")==true){
			  		 $.ajax({
			  			 async:false,
			       		url:"/api/warehouseAddress/updateWarehouseDeliveryPoint",
			       		data:{id:id,isDeliveryPoint:1},
			       		type:"POST",
			       		dataType:"json",
			       		success:function(data){
			       			if(data.code=="200"){
			       				tb.fnDraw();
			       			}else{
			       				alert(data.message);
			       			}
			       		}
			  		 });
			  		 return;
			  	 }else{
			  		 return false;
			  	 }
		   }
		   
		   //批量删除
		   function batchDelete(){
			   var num=$("input[type='checkbox'][name='checkOne']:checked").length;
			   if (num == 0) {
					alert('请至少选择一行数据'); 
					return false;
				}
			  var  ids = "";
			  $("input[type='checkbox'][name='checkOne']:checked").each(function(index){
					ids += $(this).val() + ",";
			  });
			  deleteById(ids);
		   }
		   
		   //删除方法
		   function deleteById(ids){
			   
			   if(confirm("确认删除吗")==true){
		  		 $.ajax({
		  			 async:false,
		       		url:"/api/warehouseAddress/delete",
		       		data:{warehouseAddressIds:ids},
		       		type:"POST",
		       		dataType:"json",
		       		success:function(data){
		       			if(data.code=="200"){
		       				tb.fnDraw();
		       			}else{
		       				alert(data.message);
		       			}
		       		}
		  		 });
		  		 return;
		  	 }else{
		  		 return false;
		  	 }
		   }
</script>
</body>
</html>